package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.UmsRole;
import com.itheima.mapper.UmsRoleMapper;
import com.itheima.service.UmsRoleService;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 后台用户角色表 服务实现类
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@DubboService
public class UmsRoleServiceImpl extends ServiceImpl<UmsRoleMapper, UmsRole> implements UmsRoleService {

    @Autowired
    private UmsRoleMapper umsRoleMapper;
    @Override
    public List<UmsRole> getAll() {
        return umsRoleMapper.selectAll();
    }

    @Override
    public Page<UmsRole> getListByPage(Integer pageNum, Integer pageSize, String keyword) {
        LambdaQueryWrapper<UmsRole> lqw = new LambdaQueryWrapper<>();
        Page<UmsRole> page = new Page<>(pageNum, pageSize);
        lqw.like(StringUtils.isNotEmpty(keyword), UmsRole::getName, keyword);
        return umsRoleMapper.selectPage(page, lqw);
    }

    @Override
    public Integer create(UmsRole umsRole) {
        int count = umsRoleMapper.insert(umsRole);
        return count;
    }

    @Override
    public Integer deleteByIds(List<Long> ids) {
       return umsRoleMapper.deleteBatchIds(ids);
    }

    @Override
    public Integer update(UmsRole umsRole) {
        int count = umsRoleMapper.updateById(umsRole);
        return count;
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        umsRoleMapper.updateStatus(id,status);
    }

    @Override
    public List<UmsRole> getByIds(List<Long> roleIds) {
        return umsRoleMapper.selectBatchIds(roleIds);
    }


}
